from rest_framework.serializers import ModelSerializer
from rest_framework import  serializers
from apps.goods.models import SpecificationOption,SPUSpecification

class SpecificationOptionModelSerializer(ModelSerializer):
    """规格选项表序列化器"""
    spec=serializers.StringRelatedField(read_only=True)
    spec_id=serializers.IntegerField()

    class Meta:
        model = SpecificationOption
        fields=('id','value','spec','spec_id')
        extra_kwargs = {
            'id': {'read_only':True}
        }


class SPUSpecificationModelSerializer(ModelSerializer):
    """规格选项列表序列化器"""
    spu=serializers.StringRelatedField(read_only=True)
    class Meta:
        model=SPUSpecification
        fields=('id','name','spu')
